﻿// See https://aka.ms/new-console-template for more information
using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
using ElsaWorkFlows.CustomerActivity;
using Microsoft.Extensions.DependencyInjection;

Console.WriteLine("Hello, World!");
try
{
    //1.定义工作流执行的逻辑--活动
    //2.谁来执行流程；
    //配置IOC容器来实现

    //把Elsa要执行的步骤环节，定义到一个端点中去

    //简单工作流程
    {
        ////创建IOC容器
        //ServiceCollection services = new ServiceCollection();
        ////需先引入Elsa的包
        //services.AddElsa();
        //var provider = services.BuildServiceProvider();
        //var runner = provider.GetRequiredService<IWorkflowRunner>();
        //WriteLine writeLine = new WriteLine("工作流执行1");
        //await runner.RunAsync(writeLine);
    }

    //执行多个动作
    {
        ////创建IOC容器
        //ServiceCollection services = new ServiceCollection();
        ////需先引入Elsa的包
        //services.AddElsa();
        //var provider = services.BuildServiceProvider();
        ////获取工作流的执行者
        //var runner = provider.GetRequiredService<IWorkflowRunner>();

        ////定义一个活动队列
        //Sequence sequence = new Sequence
        //{
        //    Activities = {
        //           new WriteLine("工作流步骤1")
        //         , new WriteLine("工作流步骤2")
        //         , new WriteLine("工作流步骤3")
        //         , new WriteLine("工作流步骤4")
        //         , new WriteLine("工作流步骤5")
        //    }
        //};
        //await runner.RunAsync(sequence);
    }

    //定义活动的规则
    //实现一个IActivity
    //自定义活动的方式： 1.直接实现结构IActivity 2.继承CodeActivity 3.继承Activity（指Elsa提供的）
    {
        //创建IOC容器
        ServiceCollection services = new ServiceCollection();
        //需先引入Elsa的包
        services.AddElsa();
        var provider = services.BuildServiceProvider();
        //获取工作流的执行者
        var runner = provider.GetRequiredService<IWorkflowRunner>();

        //定义一个活动队列
        Sequence sequence = new Sequence
        {
            Activities = {
                  new HelloWorld()
            }
        };
        await runner.RunAsync(sequence);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex);
}